package com.edu.demo.service.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.DesensitizedUtil;
import cn.hutool.crypto.digest.DigestUtil;
import com.edu.demo.entity.UserBean;
import com.edu.demo.entity.dto.UserLoginDTO;
import com.edu.demo.dao.IUserLoginDao;
import com.edu.demo.service.IUserLoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/*
 *
 *   @Author:max
 *   @Date: 2024/3/4-03-04-21:02
 *
 */
@Service
public class UserLoginServiceImpl implements IUserLoginService {

    @Autowired
    private IUserLoginDao iUserLoginDao;

    @Override
    public UserLoginDTO userLoginByPass(UserBean userBean) {
        System.out.println("userBean = " + userBean);
        userBean.setPassword(DigestUtil.md5Hex(userBean.getPassword()));
        System.out.println("userBean = " + userBean);
        UserBean bean = iUserLoginDao.selectUserByNameAndPass(userBean);
        //如果为空 返回空
        if (bean == null) {
            return null;
        }
        UserLoginDTO userLoginDTO = new UserLoginDTO();
        BeanUtil.copyProperties(bean, userLoginDTO);
        userLoginDTO.setPhone(DesensitizedUtil.mobilePhone(userLoginDTO.getPhone()));
        userLoginDTO.setIdCard(DesensitizedUtil.idCardNum(userLoginDTO.getIdCard(), 3, 4));
        return userLoginDTO;
    }
}
